<?php
require_once 'vendor/autoload.php';

use Illuminate\Database\Capsule\Manager as Capsule;

$capsule = new Capsule;
$capsule->addConnection([
    'driver'    => 'mysql',
    'host'      => '129.226.194.102',
    'database'  => 'aimeos_lvgang_to',
    'username'  => 'aimeos_lvgang_to',
    'password'  => 'ZQaJw6X9nksn8kt7',
    'charset'   => 'utf8mb4',
    'collation' => 'utf8mb4_unicode_ci',
    'prefix'    => '',
]);

$capsule->setAsGlobal();
$capsule->bootEloquent();

try {
    $pdo = $capsule->getConnection()->getPdo();
    
    // Create mshop_locale_site table
    $sql = "CREATE TABLE IF NOT EXISTS mshop_locale_site (
        id INT AUTO_INCREMENT PRIMARY KEY,
        parentid INT DEFAULT NULL,
        level SMALLINT NOT NULL DEFAULT 0,
        code VARCHAR(64) NOT NULL,
        label VARCHAR(255) NOT NULL,
        config TEXT,
        nleft INT NOT NULL DEFAULT 1,
        nright INT NOT NULL DEFAULT 2,
        status SMALLINT NOT NULL DEFAULT 1,
        icon VARCHAR(255) DEFAULT '',
        logo VARCHAR(255) DEFAULT '',
        rating DECIMAL(2,1) DEFAULT '0.0',
        ratings INT DEFAULT 0,
        refid VARCHAR(36) DEFAULT '',
        theme VARCHAR(32) DEFAULT '',
        mtime DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
        ctime DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
        editor VARCHAR(255) NOT NULL DEFAULT '',
        UNIQUE KEY unq_mslocsi_code (code),
        KEY idx_mslocsi_nlt_nrt (nleft, nright),
        KEY idx_mslocsi_level_status (level, status),
        KEY fk_mslocsi_pid (parentid),
        CONSTRAINT fk_mslocsi_pid FOREIGN KEY (parentid) REFERENCES mshop_locale_site (id) ON DELETE CASCADE ON UPDATE CASCADE
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;";
    
    $pdo->exec($sql);
    echo "mshop_locale_site table created successfully\n";
    
    // Insert default site data
    $insertSql = "INSERT IGNORE INTO mshop_locale_site (code, label, nleft, nright, level, status, editor) VALUES 
        ('default', 'Default', 1, 2, 0, 1, 'setup');";
    
    $pdo->exec($insertSql);
    echo "Default site data inserted successfully\n";
    
} catch (Exception $e) {
    echo "Error: " . $e->getMessage() . "\n";
}